<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<script>
    function Hash(){
        this.table=new Array(137);
    }
    Hash.prototype={
        simpleHash: function (str) {
            const H=37;
            var total= 0,size=str.length;
            while(size--){
                total+=H*total+str.charCodeAt(size);
            }
            return total % this.table.length;
        },
        show: function () {
            console.info('show data:');
            console.log(this.table);
        },
        put: function (data) {
            var pos=this.simpleHash(data);
            this.table[pos]=data;
        },
        get: function () {

        }
    }

    function random(min, max) {
        return Math.floor(Math.random()*(max-min+1))+min;
    }
    function getStuData(arr){
        for(var i=0;i<arr.length;i++){
            var num='';
            for(var j=1;j<=9;j++){
                num+=Math.floor(Math.random()*10);
            }
            num+=random(50,100);
            arr[i]=num;
        }
    }
    var students=new Array(10);
    getStuData(students);
    console.info('students:');
    for(var i=0;i<students.length;i++){
        console.log(students[i].substring(0,9),students[i].substring(9));
    }

    var hash=new Hash();
    for(var i=0;i<students.length;i++){
        hash.put(students[i]);
    }
    hash.show();



</script>
</body>
</html>